#include "Util.h"
#include <stdexcept>

namespace SEngine
{

    SphericalCoord CartesianToSpherical(const glm::vec3& cartesian) {
        SphericalCoord coord;
        coord.r = glm::length(cartesian); // 计算距离
        coord.theta = glm::acos(cartesian.y / coord.r); // 计算从正y轴到点的向量与z轴的夹角
        coord.phi = glm::atan(cartesian.x, cartesian.z); // 计算从正z轴到点的投影在xz平面上的向量与x轴的夹角
        return coord;
    }
    
    glm::vec3 SphericalToCartesian(const SphericalCoord& coord)
    {
        glm::vec3 out;
        out.y = glm::cos(coord.theta) * coord.r;
        out.z = glm::sin(coord.theta) * glm::cos(coord.phi) * coord.r;
        out.x = glm::sin(coord.theta) * glm::sin(coord.phi) * coord.r;
        return out;
    }

    glm::vec3 MixSphere(const glm::vec3& begin, const glm::vec3& end, float a) 
    {
        float length1= glm::length(begin);
        float length2= glm::length(end);
        glm::vec3 mixed = glm::mix(begin, end, a);
        mixed = mixed / glm::length(mixed) * (length1 + length2) / 2.0f;
        return mixed;
    }

}
